package com.neuedu.corejava.ch10;

import java.util.TreeSet;

public class TreeSetClass {

	public static void main(String[] args) {
		
		//TreeSet保存的数据类型需要实现java.lang.Comparable接口
		//在保存数据时会进行类型检查，如果没有实现java.lang.Comparable接口会报类型转换异常java.lang.ClassCastException
		TreeSet<Computer> treeSet=new TreeSet<Computer>();
		treeSet.add(new Computer("hw13",5230));
		treeSet.add(new Computer("hw23",5430));
		treeSet.add(new Computer("hp1",5046));
		treeSet.add(new Computer("hp2",50364));
		treeSet.add(new Computer("dell1",52420));
		treeSet.add(new Computer("dell2",54430));
		
		Computer computer=treeSet.first();
		Computer computer2=treeSet.last();
		System.out.println(computer);
		System.out.println(computer2);
		System.out.println("==================");
		
		//以队列形式进行操作
		computer =treeSet.pollFirst();
		while(computer!=null) {
			System.out.println(computer);
			computer=treeSet.pollFirst();
		}
	}
}
